package com.ems.controller;

import com.ems.config.LogPointer;
import com.ems.entity.UserEntity;
import com.ems.service.IMenuService;
import com.ems.util.RedisUtils;
import com.ems.vo.BaseResult;
import com.ems.vo.MenuVo;
import com.ems.vo.UserVo;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 菜单权限表 前端控制器
 * </p>
 * @author WuZH
 * @since 2023-10-24
 */
@RestController
@RequestMapping ("/menu")
@CrossOrigin (value = "*", maxAge = 3600)
public class MenuController {

    @Resource
    private IMenuService iMenuService;

    @RequestMapping ("queryList")
    @LogPointer ("菜单路由列表")
    public BaseResult queryList (@RequestBody MenuVo menuVo) {
        List<MenuVo> menuVos = iMenuService.queryList ( menuVo );
        return BaseResult.success ( menuVos, iMenuService.queryCount ( menuVo ) );
    }

    /**
     * 查询系统中所有菜单路由，用于赋权
     * @param menuVo
     * @return
     */
    @RequestMapping ("getList")
    @LogPointer ("查询菜单列表")
    public BaseResult getList (@RequestBody MenuVo menuVo) {
        menuVo.setType ( 1 );
        List<MenuVo> menuEntities = iMenuService.getList ( menuVo );
        return BaseResult.success ( menuEntities );
    }

    @RequestMapping ("saveSingle")
    @LogPointer ("新增菜单")
    public BaseResult saveSingle (@RequestBody MenuVo menuVo) {
        MenuVo vo = iMenuService.saveSingle ( menuVo );
        return BaseResult.success ( vo );
    }

    /**
     * 通过角色Id获取对应的权限路由
     * @param menuVo
     * @return
     */
    @RequestMapping ("queryRoleMenus")
    @LogPointer ("登录用户获取权限路由")
    public BaseResult queryRoleMenus (@RequestBody MenuVo menuVo) {
        List<MenuVo> menuVos = iMenuService.queryMenus ( menuVo );
        return BaseResult.success ( menuVos );
    }

}
